﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClientAppViaWebService.ResearchDivisionsLogicServiceRef;

namespace ClientAppViaWebService.Forms
{
    public partial class ResearchDivisionEditForm : DivisionEditForm
    {
        private ResearchDivisionsLogicService lService;
        private readonly Int32 ClassID = 3;

        public ResearchDivisionEditForm()
        {
            InitializeComponent();
            lService = new ResearchDivisionsLogicService();
            classTextBox.Text = ClassID.ToString();
        }

        public String Purpose
        {
            get { return purposeTextBox.Text; }
            set { purposeTextBox.Text = value; }
        }

        public Decimal Financing
        {
            get { return Decimal.Parse(financingTextBox.Text); }
            set { financingTextBox.Text = value.ToString(); }
        }

        public String Sponsors
        {
            get { return sponsorsTextBox.Text; }
            set { sponsorsTextBox.Text = value; }
        }

        public String Awards
        {
            get { return awardsTextBox.Text; }
            set { awardsTextBox.Text = value; }
        }

        protected override void SetFormProperties(Object _object)
        {
            ResearchDivision d = (_object as ResearchDivision);
            ID = d.ID;
            EXT_ID = d.EXT_ID;
            ParentId = d.PARENT_ID;
            Class = d.CLASS_ID;
            ObjName = d.NAME;
            BossName = d.BOSS_ID;
            DateCreated = d.DATE_CREATED;
            Description = d.DESCRIPTION;
            Financing = d.FINANCING;
            Sponsors = d.SPONSORS;
            Purpose = d.PURPOSE;
            Awards = d.AWARDS;
        }

        protected override Object RetrieveFormProperties()
        {
            ResearchDivision division = new ResearchDivision();
            division.ID = ID;
            division.EXT_ID = EXT_ID;
            division.PARENT_ID = ParentId;
            division.CLASS_ID = Class;
            division.NAME = ObjName;
            division.DataBaseName = DataBaseName;
            division.BOSS_ID = BossName;
            division.DATE_CREATED = DateCreated;
            division.DESCRIPTION = Description;
            division.FINANCING = Financing;
            division.SPONSORS = Sponsors;
            division.PURPOSE = Purpose;
            division.AWARDS = Awards;
            return division;
        }

        protected override void LoadEditFormData(int parentNodeID)
        {
            ResearchDivision p = lService.SelectResearchDivision_By_DataBase_And_Id(DataBaseName, parentNodeID);
            SetFormProperties(p);
        }

        protected override void UpdateEntity()
        {
            ResearchDivision obj = RetrieveFormProperties() as ResearchDivision;
            lService.UpdateResearchDivision(obj);
        }

        protected override void InsertEntity()
        {
            ResearchDivision obj = RetrieveFormProperties() as ResearchDivision;
            lService.InsertResearchDivision(obj);
        }
    }
}
